package com.doupi.partner.op.controller.configure;

import com.doupi.partner.util.DataTableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.doupi.partner.dal.model.OperationLog;
import com.doupi.partner.service.OperationLogService;
import com.doupi.partner.util.Pagination;

@Controller
@RequestMapping("configure/operationLog")
public class OperationLogController {
	private final static String TEMPLATE_FOLDER = "configure/";

	private final OperationLogService operationLogService;

	@Autowired
	public OperationLogController(OperationLogService operationLogService) {
		this.operationLogService = operationLogService;
	}

	@RequestMapping(value = "index", method = RequestMethod.GET)
	public String index() {
		return TEMPLATE_FOLDER + "operationLog/index";
	}

	@ResponseBody
	@RequestMapping(value = "list", method = RequestMethod.POST)
	public DataTableData<OperationLog> list(Integer offset, Integer limit, OperationLog operationLog) {
		Pagination<OperationLog, OperationLog> pagination = new Pagination<>(offset, limit, operationLog);
		pagination = operationLogService.queryOperationLogs(pagination);
		return new DataTableData<>(pagination.getTotalCount(), pagination.getRecords());
	}
}
